Imports System.Data.SqlClient
Public Class cls_maquinariamaquinariatarea_

    Implements ICloneable

#Region "Variables ..."
    Private int_idmaquinariamaquinariatarea As Integer = 0
    Private int_idmaquinaria As Integer = 0
    Private int_idmaquinariatarea As Integer = 0

    Private obj_maquinaria As cls_maquinaria_
    Private obj_maquinariatarea As cls_maquinariatarea_

    Private col_Items As Collections.Generic.List(Of cls_maquinariamaquinariatarea_) = Nothing
#End Region

    Public Overrides Function ToString() As String
        Return maquinaria.ToString
    End Function

#Region "Propiedades ..."
    ReadOnly Property This
        Get
            Return Me
        End Get
    End Property
    ReadOnly Property ThisDescripcion As String
        Get
            Return Me.ToString
        End Get
    End Property
    ReadOnly Property pKey
        Get
            Return idmaquinariamaquinariatarea
        End Get
    End Property
    Property idmaquinariamaquinariatarea() As Integer
        Get
            idmaquinariamaquinariatarea = int_idmaquinariamaquinariatarea
        End Get
        Set(ByVal value As Integer)
            int_idmaquinariamaquinariatarea = value
        End Set
    End Property
    Property idmaquinaria() As Integer
        Get
            idmaquinaria = int_idmaquinaria
        End Get
        Set(ByVal value As Integer)
            int_idmaquinaria = value
        End Set
    End Property
    Property idmaquinariatarea() As Integer
        Get
            idmaquinariatarea = int_idmaquinariatarea
        End Get
        Set(ByVal value As Integer)
            int_idmaquinariatarea = value
        End Set
    End Property
    Property maquinaria() As cls_maquinaria_
        Get
            If IsNothing(obj_maquinaria) Then
                obj_maquinaria = New cls_maquinaria_
                If Not obj_maquinaria.Buscar(idmaquinaria) Then
                    obj_maquinaria = Nothing
                End If
            End If
            maquinaria = obj_maquinaria
        End Get
        Set(ByVal value As cls_maquinaria_)
            obj_maquinaria = value
        End Set
    End Property
    Property maquinariatarea() As cls_maquinariatarea_
        Get
            If IsNothing(obj_maquinariatarea) Then
                obj_maquinariatarea = New cls_maquinariatarea_
                If Not obj_maquinariatarea.Buscar(idmaquinariatarea) Then
                    obj_maquinariatarea = Nothing
                End If
            End If
            maquinariatarea = obj_maquinariatarea
        End Get
        Set(ByVal value As cls_maquinariatarea_)
            obj_maquinariatarea = value
        End Set
    End Property
    Property Items() As Collections.Generic.List(Of cls_maquinariamaquinariatarea_)
        Get
            Items = col_Items
        End Get
        Set(ByVal value As Collections.Generic.List(Of cls_maquinariamaquinariatarea_))
            col_Items = value
        End Set
    End Property
#End Region

    Private Sub CargarColeccion(ByVal obj_Reader As SqlDataReader)
        col_Items = New Collections.Generic.List(Of cls_maquinariamaquinariatarea_)
        While obj_Reader.Read()
            Dim Elemento As New cls_maquinariamaquinariatarea_
            Elemento.int_idmaquinariamaquinariatarea = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinariamaquinariatarea")))

            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinaria"))) = False Then
                Elemento.int_idmaquinaria = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinaria")))
            End If
            If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinariatarea"))) = False Then
                Elemento.int_idmaquinariatarea = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinariatarea")))
            End If
            col_Items.Add(Elemento)
        End While
    End Sub

    Private Sub CargarVariables(ByVal obj_Reader As SqlDataReader)
        obj_Reader.Read()
        int_idmaquinariamaquinariatarea = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinariamaquinariatarea")))

        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinaria"))) = False Then
            int_idmaquinaria = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinaria")))
        End If
        If IsDBNull(obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinariatarea"))) = False Then
            int_idmaquinariatarea = (obj_Reader.GetValue(obj_Reader.GetOrdinal("idmaquinariatarea")))
        End If
    End Sub

    Public Function Nuevo(Optional ByVal ObtenerID As Boolean = False) As Boolean
        Nuevo = False
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__Nuevo"
                .Parameters.Add("@idmaquinaria", SqlDbType.Int).Value = int_idmaquinaria
                .Parameters.Add("@idmaquinariatarea", SqlDbType.Int).Value = int_idmaquinariatarea
                .ExecuteNonQuery()
            End With
            Nuevo = True
            If ObtenerID Then
                CargarUltimo()
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Crear el registro de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Function

    Public Sub Modificar()
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__Modificar"
                .Parameters.Add("@idmaquinariamaquinariatarea", SqlDbType.Int).Value = int_idmaquinariamaquinariatarea
                .Parameters.Add("@idmaquinaria", SqlDbType.Int).Value = int_idmaquinaria
                .Parameters.Add("@idmaquinariatarea", SqlDbType.Int).Value = int_idmaquinariatarea
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Modificar el registro de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Sub Eliminar(ByVal idmaquinariamaquinariatarea As Integer)
        Dim obj_Conexion As New cls_Conexion
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__Eliminar"
                .Parameters.Add("@idmaquinariamaquinariatarea", SqlDbType.Int).Value = idmaquinariamaquinariatarea
                .ExecuteNonQuery()
            End With
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Eliminar el registro de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
        End Try
    End Sub

    Public Function Buscar(ByVal idmaquinariamaquinariatarea As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            Buscar = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__Buscar"
                .Parameters.Add("@idmaquinariamaquinariatarea", SqlDbType.Int).Value = idmaquinariamaquinariatarea
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
                Buscar = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al Buscar el registro de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Sub CargarUltimo()
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__CargarUltimo"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarVariables(obj_Reader)
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarUltimo registro de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Sub

    Public Function CargarTodos() As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarTodos = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__CargarTodos"
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarTodos = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarTodos los registros de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function CargarXidmaquinaria(ByVal int_idmaquinaria As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXidmaquinaria = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__CargarXidmaquinaria"
                .Parameters.Add("@idmaquinaria", SqlDbType.Int).Value = int_idmaquinaria
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXidmaquinaria = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarXidmaquinaria los registros de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function CargarXidmaquinariatarea(ByVal int_idmaquinariatarea As Integer) As Boolean
        Dim obj_Conexion As New cls_Conexion
        Dim obj_Reader As SqlDataReader
        Try
            CargarXidmaquinariatarea = False
            obj_Conexion.Conectar()
            With obj_Conexion.obj_SqlCommand
                .CommandType = CommandType.StoredProcedure
                .Connection = obj_Conexion.obj_SqlConnection
                .CommandText = "maquinariamaquinariatarea__CargarXidmaquinariatarea"
                .Parameters.Add("@idmaquinariatarea", SqlDbType.Int).Value = int_idmaquinariatarea
            End With
            obj_Reader = obj_Conexion.obj_SqlCommand.ExecuteReader
            If obj_Reader.HasRows Then
                CargarColeccion(obj_Reader)
                CargarXidmaquinariatarea = True
            End If
        Catch ex As SqlClient.SqlException
            Throw New Exception("Error al CargarXidmaquinariatarea los registros de maquinariamaquinariatarea_." & Chr(13) & _
           "Por favor informe del siguiente detalle técnico:" & Chr(13) & _
           "Nro de error: " & ex.ErrorCode & "." & Chr(13) & _
           "Descripción: " & ex.Message)
        Finally
            obj_Conexion.Desconectar()
            obj_Conexion = Nothing
            obj_Reader = Nothing
        End Try
    End Function

    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim obj_maquinariamaquinariatarea_Clon As New cls_maquinariamaquinariatarea_
        obj_maquinariamaquinariatarea_Clon.int_idmaquinariamaquinariatarea = Me.int_idmaquinariamaquinariatarea
        obj_maquinariamaquinariatarea_Clon.int_idmaquinaria = Me.int_idmaquinaria
        obj_maquinariamaquinariatarea_Clon.int_idmaquinariatarea = Me.int_idmaquinariatarea
        obj_maquinariamaquinariatarea_Clon.col_Items = Me.col_Items
        Return obj_maquinariamaquinariatarea_Clon
    End Function

  

End Class
